let caseDataArr = [
  {
    name: 'case1-json复制',
    inputData: '{"name":"张三","age":18,"sex":"男dsfdsfsdfafafafasfasf地方撒阿萨阿萨法守法萨法所发生的啊沙发上啊沙发上阿斯蒂芬","obj":{"name":"张三","age":18}}',
    outputData: ""
  },
  {
    name: 'case2-分割数组',
    inputData: 'a12\nad,233\ncc，多福多寿、吵\n',
    outputData: ""
  },
  {
    name: 'case3-表数组',
    inputData: 'a\tb\tc，诶\n',
    outputData: ""
  },
  {
    name: 'case4-行转对象',
    inputData: 'a\nb\nc，哎',
    outputData: ""
  },
  {
    name: 'case5-顺序赋值',
    inputData: '{"name":"张三","age":18,"sex":"男dsfdsfsdfafafafasfasf地方撒阿萨阿萨法守法萨法所发生的啊沙发上啊沙发上阿斯蒂芬","obj":{"name":"张三","age":18},"f1":"fdsf","f2":false,"f3":null,"f4":"fff"}',
    outputData: "age\nname\nsex\nobj\n\npass\npass\nf4\nf45"
  },
  {
    name: 'case6-行转对象',
    inputData: "a\t2\nb\tb2\nc，哎\t\nd,d_value\t\n",
    outputData: ""
  },
  {
    name: 'case7-表2对象数组',
    inputData: "a\tb\tc\n1\t2\t3\nd1\td2\tc3\nd2\td3\tc4\nd3\td4\tc5\n",
    outputData: ""
  },
  {
    name: 'case8-数组简化',
    inputData: "[\"a12\",\"ad,233\",\"cc，多福多寿、吵\"]",
    outputData: ""
  },
  {
    name: 'case9-时间戳转str',
    inputData: "1736516202251",
    outputData: ""
  },
  {
    name: 'case10-时间str转时间戳',
    inputData: "2025-01-10 21:46:35",
    outputData: ""
  },
  {
    name: 'case11-数组计算',
    inputData: "1\n2\n3\n4\n",
    outputData: "0\n3\n4\n5\n"
  },
  {
    name: 'case14-数组转Excel',
    inputData: "[\n  {\n    \"a\": \"1\",\n    \"b\": \"2\",\n    \"c\": \"3\"\n  },\n  {\n    \"a\": \"d1\",\n    \"b\": \"d2\",\n    \"c\": \"c3\"\n  },\n  {\n    \"a\": \"d2\",\n    \"b\": \"d3\",\n    \"c\": \"c4\"\n  },\n  {\n    \"a\": \"d3\",\n    \"b\": \"d4\",\n    \"c\": \"c5\"\n  }\n]",
    outputData: ""
  },
  {
    name: 'case15-字符串替换',
    inputData: "{\n    \"key1\": \"{0}\",\n    \"key2\": \"{1}\",\n    \"key3\": \"{2}\"\n},\n",
    outputData: "a\tb\tc\t\n1\t2\t3\t\nd1\td2\tc3\t\nd2\td3\tc4\t\nd3\td4\tc5\t\n"
  },
  {
    name: 'case16-url转义',
    inputData: "https://gitee.com/luduanxu/string_util?jj=解决",
    outputData: ""
  },
  {
    name: 'case17-url解析',
    inputData: "https://gitee.com/luduanxu/string_util?jj=%E8%A7%A3%E5%86%B3",
    outputData: ""
  },
  {
    name: 'case18-结果转到输入',
    inputData: '{"nfsdddme":"张三","age":18,"ssdfsffsex":"男dsfdsfsdfafafafasfasf地sfdasfsfasfsaf方撒阿萨阿萨法守法萨法所发生的啊沙发上啊沙发上阿斯蒂芬","be":true,"be2":false,"null":null,"jsonStr":"{\\"name\\":\\"张三\\",\\"age\\":18}","arr":[1,2,3,4,5],"obj1":{"name":"张三","age":18}}',
    outputData: '{"nfsdddme":"张3322三","age":88,"ssdfsffsex":"说法萨芬","be":true,"be2":true,"null":null,"jsonStr":"{\\"name\\":\\"张666三\\",\\"age\\":66}","arr":[1,2],"obj1":{"name":"张212三","name+":"张66","age":18}}'
  },
  {
    name: 'case19-字符串替换1',
    inputData: '{\n  "key1": "{c}",\n  "key1": "{a}",\n  "key2": "{b}",\n  "key3": "{c}"\n},\n',
    outputData: '[{"a":"1","b":"2","c":"3"},{"a":"d1","b":"d2","c":"c3"},{"a":"d2","b":"d3","c":"c4"},{"a":"d3","b":"d4","c":"c5"}]'
  },
]

let actionDataInit = [
  // 行
  [
    // 分组
    {
      name: '<b>&nbsp;&nbsp;JSON: &nbsp;</b>',
      class: '',
      arr: [
        {
          txt: 'json格式',
          fun: (that) => {
            that.dataChangeOnly()
            if(!that.validateInput()) return
            that.outputStr = JSON.stringify(JSON.parse(that.inputStr), null, 2)
          },
          desc: '复制json格式化后的字符串（参考case1-json复制）',
          type: 'success',
          copyOutputStr: true
        },
        {
          txt: 'json压缩',
          fun: (that) => {
            that.dataChangeOnly()
            if(!that.validateInput()) return
            that.outputStr = JSON.stringify(JSON.parse(that.inputStr))
          },
          desc: '复制json格式化后的字符串（参考case1-json复制）',
          type: 'success',
          copyOutputStr: true
        },

        {
          txt: '分割数组',
          fun: (that) => {
            that.dataChangeOnly()
            if(!that.validateInput()) return
            let arr = that.inputStr.replaceAll(/[，,]/g, '\n')
              .split('\n').map(item => item.trim()).filter(item => item !== "");
            that.outputStr = jsonToStrFormat(arr)
          },
          desc: '行、逗号都会转一个元素（case2-分割数组）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '行转数组',
          fun: (that) => {
            if(!that.validateInput()) return
            let arr = that.inputStr.replaceAll(/"/g, '')
              .split('\n').map(item => item.trim()).filter(item => item !== "");
            that.outputStr = jsonToStrFormat(arr)
          },
          desc: '行转为数组（参考case2-分割数组）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '表数组',
          fun: (that) => {
            if(!that.validateInput()) return
            let arr = that.inputStr.replaceAll(/[，,]/g, '\t')
              .split('\t').map(item => item.trim()).filter(item => item !== "");
            that.outputStr = jsonToStrFormat(arr)
          },
          desc: 'Excel表一行转数组（参考case3-表数组）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '行转对象',
          fun: (that) => {
            if(!that.validateInput()) return
            let rep = '\n'
            let arr = that.inputStr.replaceAll(/[，,]/g, rep)
              .split(rep).map(item => item.trim()).filter(item => item !== "");
            let obj = {}
            arr.forEach(item => {
              obj[item] = ''
            })
            that.outputStr = jsonToStrFormat(obj)
          },
          desc: '每行、逗号变为对象的一个属性（参考case4-行转对象）',
          type: '',
          copyOutputStr: true
        },

        {
          txt: 'key数组',
          fun: (that) => {
            if(!that.validateInput()) return
            let obj = JSON.parse(that.inputStr)
            if (that.inputType === 'obj') {
              obj = that.inputObj
            }
            that.outputStr = jsonToStrFormat(Object.keys(obj))
          },
          desc: '复制对象key为数组（参考case1-json复制）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '值数组',
          fun: (that) => {
            if(!that.validateInput()) return
            let obj = JSON.parse(that.inputStr)
            if (that.inputType === 'obj') {
              obj = that.inputObj
            }
            that.outputStr = jsonToStrFormat(Object.values(obj))
          },
          desc: '复制对象值为数组（参考case1-json复制）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '值初始化',
          fun: (that) => {
            if (that.inputType === 'str') {
              if (that.inputStr === "") {
                that.$message.warning("请输入数据");
                return;
              }
              that.inputObj = strToJson(that.inputStr)
            }
            initObj(that.inputObj);
            that.inputStr = JSON.stringify(that.inputObj, null, 2)
            that.inoutObjReference()
            that.outputStr = that.inputStr
          },
          desc: '对象值初始化（参考case1-json复制）',
          type: '',
          copyOutputStr: true
        },

        {
          txt: '顺序赋值',
          fun: (that) => {
            if(!that.validateInput()) return
            let arr = that.outputStr.replaceAll(/[,\t]/g, '\n').split('\n').map(item => item.trim());
            that.dataChangeOnly()
            if (that.inputObj instanceof Array) {
              that.inputObj.forEach(item => setObjVal(item, arr))
            } else {
              setObjVal(that.inputObj, arr)
            }
            that.inputStr = JSON.stringify(that.inputObj, null, 2);
            that.outputStr = that.inputStr
            that.inoutObjReference()
            that.copyTextIn(that.inputStr)
          },
          desc: '将结果中按【行、英文逗号、\t】对应顺序赋值；跳过的字段使用【pass】跳过（case5-顺序赋值）',
          type: ''
        },

        {
          txt: '结果转到输入',
          fun: (that) => {
            that.dataChangeOnly()
            if (that.inputStr === '' || that.outputStr === '') {
              msgWarning("有对象为空，请输入")
            }
            try {
              let fromObj = JSON.parse(that.outputStr)
              let toObj = JSON.parse(that.inputStr)
              assignValues(fromObj, toObj, 0)
              that.inputObj = toObj
              that.inputStr = jsonToStrFormat(toObj)
              copyTextIn(that.inputStr)
            } catch (e) {
              that.$message.warning("有字符串错误。")
            }
          },
          desc: '值复制，结果对象中可以复制到输入对象（case18-结果转到输入）',
          type: ''
        },
        {
          txt: '行2对象',
          fun: (that) => {
            if(!that.validateInput()) return
            let arr = that.inputStr.split('\n').map(item => item.trim()).filter(item => item !== "");
            let obj = {}

            arr.forEach(item => {
              const one = item.split('\t');
              if (one.length === 2) {
                const key = one[0].trim();
                obj[key] = one[1].trim()
              } else {
                const eq = item.split('=')
                if (eq.length === 2) {
                  const key = eq[0].trim();
                  obj[key] = eq[1].trim()
                } else {
                  const eq = item.split(':')
                  if (eq.length === 2) {
                    const key = eq[0].trim();
                    obj[key] = eq[1].trim()
                  } else {
                    const eq = item.split(',')
                    if (eq.length === 2) {
                      const key = eq[0].trim();
                      obj[key] = eq[1].trim()
                    } else {
                      obj[item] = ''
                    }
                  }
                }
              }
            })
            that.outputStr = jsonToStrFormat(obj)
          },
          desc: '行转对象，key、value使用 \\t ,分割（case6-行转对象）',
          type: ''
        },
        {
          txt: '表2对象数组',
          fun: (that) => {
            if(!that.validateInput()) return
            let arr = that.inputStr.split('\n').map(item => item.trim()).filter(item => item !== "");
            let objs = []
            let keys = arr[0].split('\t')
            for (let i = 1; i < arr.length; i++) {
              let one = arr[i].split('\t')
              let obj = {}
              for (let j = 0; j < keys.length; j++) {
                if (one[j] && (one[j].includes("\\n") || one[j].includes("\\t"))) {
                  obj[keys[j]] = one[j].replaceAll("\\n", "\n").replaceAll("\\t", "\t")
                } else {
                  obj[keys[j]] = one[j]
                }
              }
              objs.push(obj)
            }
            that.outputStr = jsonToStrFormat(objs)
          },
          desc: '表2对象数组（参考case7-表2对象数组）',
          type: 'success',
          copyOutputStr: true
        }
      ]
    }
  ],
  [
    {
      name: '<b>&nbsp;&nbsp;SQL: &nbsp;</b>',
      class: 'light_blue',
      arr: [
        {
          txt: '行转数组',
          fun: (that) => {
            if(!that.validateInput()) return
            let arr = that.inputStr.replaceAll(/[，,]/g, "\n")
              .split("\n").map(item => item.trim()).filter(item => item !== "");
            that.outputStr = JSON.stringify(arr).replace('["', '(\'').replace('"]', '\')').replaceAll('","', "','")
          },
          desc: '行转数组（case2-行转数组）',
          type: '',
          copyOutputStr: true
        }
      ]
    },
    {
      name: '<b>&nbsp;&nbsp;数组计算: &nbsp;</b>',
      class: 'light_pink',
      arr: [
        {
          txt: '输入差集输出',
          fun: (that) => {
            if(!that.validateInput()) return
            if(!that.validateOutput()) return

            let inputArr = that.getArr(that.inputStr)
            let outputArr = that.getArr(that.outputStr)
            let result = inputArr.filter(item => !outputArr.includes(item))
            that.outputStr = result.join("\n")
          },
          desc: '输入减去输出集合，数据可数组、可换行（case11-数组计算）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '输入∪输出',
          fun: (that) => {
            if(!that.validateInput()) return
            if(!that.validateOutput()) return

            let inputArr = that.getArr(that.inputStr)
            let outputArr = that.getArr(that.outputStr)
            let result = inputArr.filter(item => outputArr.includes(item))
            that.outputStr = result.join("\n")
          },
          desc: '输入、输出交集，数据可数组、可换行（case11-数组计算）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '输入∩输出',
          fun: (that) => {
            if(!that.validateInput()) return
            if(!that.validateOutput()) return

            let inputArr = that.getArr(that.inputStr)
            let outputArr = that.getArr(that.outputStr)
            let result = new Set([...inputArr, ...outputArr]);
            that.outputStr = Array.from(result).join("\n")
          },
          desc: '输入、输出并集，数据可数组、可换行（case11-数组计算）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '数组简化',
          fun: (that) => {
            that.copyTextIn(that.inputStr)
          },
          desc: '分割字符串、字符串数组去除括号、双引号（case8-数组简化）',
          type: '',
          copyOutputStr: true
        }
      ]
    },
    {
      name: '',
      class: '',
      arr: [
        {
          txt: 'one2json',
          fun: (that) => {
            that.copyTextIn(that.inputStr)
          },
          desc: 'oneApi参数说明转json',
          type: '',
          copyOutputStr: true
        },
      ]
    },
    {
      name: '',
      class: 'light_brown',
      arr: [
        {
          txt: '当前时间戳',
          fun: (that) => {
            that.outputStr = String(new Date().getTime())
          },
          desc: '获取当前时间戳（毫秒值）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '当前时间',
          fun: (that) => {
            that.outputStr = dataToStr(new Date())
          },
          desc: '获取当前时间（yyyy-MM-dd HH:mm:ss）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '时间戳2通用格式',
          fun: (that) => {
            if(!that.validateInput()) return
            let l = Number(that.inputStr)
            that.outputStr = dataToStr(l)
          },
          desc: '时间戳转通用格式（case9-时间戳转yyyy-MM-dd HH:mm:ss）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '通用格式2时间戳',
          fun: (that) => {
            if(!that.validateInput()) return
            let d = new Date(that.inputStr)
            that.outputStr = d.getTime()
          },
          desc: '通用格式转时间戳毫秒值（case10- yyyy-MM-dd HH:mm:ss转时间戳）',
          type: '',
          copyOutputStr: true
        },
      ]
    },
    {
      name: '',
      class: '',
      arr: [
        {
          txt: '数组2Excel',
          fun: (that) => {
            that.dataChangeOnly()
            if(!that.validateInput()) return
            if (!Array.isArray(that.inputObj)) {
              return;
            }
            let keyIndObj = {}
            let keyInd = 0
            let arr = []
            for (const objOne of that.inputObj) {
              for (const objOneKey in objOne) {
                if (keyIndObj[objOneKey] === undefined) {
                  keyIndObj[objOneKey] = keyInd
                  keyInd++
                }
              }
            }

            let arrTitle = []
            for (let i = 0; i < keyInd; i++) {
              arrTitle.push(i)
            }
            for (const keyIndObjKey in keyIndObj) {
              arrTitle[keyIndObj[keyIndObjKey]] = keyIndObjKey
            }
            arr.push(arrTitle)

            for (const objOne of that.inputObj) {
              let arrOne = []
              for (const objOneKey in objOne) {
                arrOne[keyIndObj[objOneKey]] = objOne[objOneKey]
              }
              arr.push(arrOne)
            }

            that.outputStr = ''
            for (const row of arr) {
              for (const coll of row) {
                if (typeof coll === "object") {
                  that.outputStr += JSON.stringify(coll) + '\t'
                } else {
                  // 如果coll包含换行符、制表符，则加上引号
                  if (coll && (coll.includes('\n') || coll.includes('\t'))) {
                    that.outputStr += coll.replaceAll(/\n/g, '\\n').replaceAll(/\t/g, '\\t') + '\t'
                  } else {
                    that.outputStr += coll + '\t'
                  }
                }
              }
              that.outputStr += '\n'
            }
          },
          desc: '对象数组转Excel表（case14-数组转Excel）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '字符串替换',
          fun: (that) => {
            that.dataChangeOnly()
            if(!that.validateInput()) return
            if(!that.validateOutput()) return

            let rows = that.outputStr.split("\n")
            let rowCols = []
            for (const row of rows) {
              if (row === "") {
                continue
              }
              rowCols.push(row.split('\t'))
            }
            that.outputStr = ''

            for (const row of rowCols) {
              let st = that.inputStr + ''
              for (let i = 0; i < row.length; i++) {
                st = st.replaceAll('{' + i + '}', row[i])
              }
              that.outputStr += st
            }
          },
          desc: '结果中制表符 -> 替换输入替换字符串生成多条数据（case15-字符串替换）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: '字符串替换1',
          fun: (that) => {
            that.dataChangeOnly()
            if(!that.validateInput()) return
            if(!that.validateOutput()) return

            let dataArr = strToJson(that.outputStr)
            that.outputStr = ''
            for (const one of dataArr) {
              let st = that.inputStr + ''
              for (const oneKey in one) {
                st = st.replaceAll('{' + oneKey + '}', one[oneKey])
              }
              that.outputStr += st
            }
          },
          desc: '结果为json数组 -> 替换输入替换字符串生成多条数据（case19-字符串替换1）',
          type: '',
          copyOutputStr: true
        },
      ]
    },
    {
      name: '',
      class: 'light_blue',
      arr: [
        {
          txt: 'url转义',
          fun: (that) => {
            if(!that.validateInput()) return
            that.outputStr = that.inputStr.replace(/([^:/?#]+)=([^&#]*)/g, (match, key, value) => {
              return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
            });
          },
          desc: 'url转义（case16-url转义）',
          type: '',
          copyOutputStr: true
        },
        {
          txt: 'url解析',
          fun: (that) => {
            if(!that.validateInput()) return
            that.outputStr = that.inputStr.replace(/([^:/?#]+)=([^&#]*)/g, (match, key, value) => {
              return `${decodeURIComponent(key)}=${decodeURIComponent(value)}`;
            });
          },
          desc: 'url解析（case17-url解析）',
          type: '',
          copyOutputStr: true
        },
      ]
    },
  ]
]

let partColorClass = [
  'white',
  'light-blue-green',
  'light_pink',
  'light_blue',
  'light_brown',
  'light_gray_green',
]

let btnClass = [
  {
    label: '主要按钮',
    value: 'primary'
  },
  {
    label: '成功按钮',
    value: 'success'
  },
  {
    label: '警告按钮',
    value: 'warning'
  },
  {
    label: '危险按钮',
    value: 'danger'
  },
  {
    label: '信息按钮',
    value: 'info'
  },
  {
    label: '文本按钮',
    value: 'text'
  },
  {
    label: '默认按钮',
    value: ''
  },
]

let settingArr = [
  {
    command: "settingBtn",
    label: "页面按钮设置",
    desc: "页面操作按钮设置，包括增加、移动位置、删除等"
  },
  {
    command: "exportConfigData",
    label: "按钮配置导出",
    desc: "页面按钮设置数据导出"
  },
  {
    command: "importConfigData1",
    label: "按钮配置导入-覆盖",
    desc: "页面按钮设置数据导入，覆盖原有配置"
  },
]

let btnObj = {
  children: [],
  id: 1,
  label: '名称',
  // 按钮
  type: 'btn',
  // 按钮对象数据
  data: {},
  // row class btn
  btnCls: 'class',
  // 样式
  class: 'light-blue-green',
  // 是否这是
  display: true,
}

let indexData = {
  message: '测试开始',
  inputType: 'str',
  inputStr: "",
  inputObj: {},
  lines: 0,
  linesOut: 0,
  outputStr: '',
  displayRight: true,
  leftClass: 'left',
  rightClass: 'right',
  inputClass: 'input',
  childrenJsonDisplay: true,
  jsonNameDialog: false,
  jsonName: '',
  saveData: [],
  thisDataObj: {},
  caseObj: {},
  caseData: caseDataArr,
  actionData: actionDataInit,
  uploadFlag: false,
  uploadData: [],
  updateFlag: false,
  updateActionArr: [],
  filterActionText: '',
  hasConfig: false,
  settingArr: settingArr,
  btnUpdateTitle: '增加按钮',
  btnUpdateFlag: false,
  btnUpdateData: {},
  btnUpdateDataBk: {},
  partColorClass: partColorClass,
  btnClass: btnClass,
  btnAddFlag: true,
  btnObjAddDemo: btnObj,
  hideBtnArr: [],
  hiddenFlag: false,
  uploadBtnConfigFlag: false,
  checkPassFlag: true
}